package site.xuxingcan.cheatgps;

import android.support.v7.app.AppCompatActivity;
import android.os.Bundle;
import android.view.View;
import android.widget.EditText;
import android.widget.Toast;

public class MainActivity extends AppCompatActivity {

    private EditText input;
    private LocationPoint locPoint;

    @Override
    protected void onCreate(Bundle savedInstanceState) {
        CheatGPSManager.getInstance().init(this);
        super.onCreate(savedInstanceState);
        setContentView(R.layout.activity_main);
        input = (EditText) findViewById(R.id.input);
        findViewById(R.id.button).setOnClickListener(new View.OnClickListener() {
            @Override
            public void onClick(View view) {
                try {
                    String text = input.getText().toString();
                    String[] split = text.split(",");
                    if (split.length == 2) {
                        double lat = Double.parseDouble(split[0].trim());
                        double lon = Double.parseDouble(split[1].trim());
                        locPoint = new LocationPoint(lat, lon);
                        if (CheatGPSManager.getInstance().isStarted()) {
                            CheatGPSManager.getInstance().goToLocation(locPoint);
                        } else {
                            CheatGPSManager.getInstance().start(locPoint);
                        }
                    }
                    Toast.makeText(MainActivity.this, "设置成功！", Toast.LENGTH_LONG).show();
                } catch (Exception e) {
                    Toast.makeText(MainActivity.this, "输入有误，请重新输入！", Toast.LENGTH_LONG).show();
                }
            }
        });
    }
}